package org.itboys.core.controller.front;


import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.core.dto.advertisment.SundayAdvertisementDto;
import org.itboys.core.entity.mongo.SundayAdvertisement;
import org.itboys.core.util.ResponseMessage;
import org.itboys.core.service.mongo.front.SundayFrontAdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 作者：zzq
 * 日期：2018年9月4日
 * 描述：广告（新闻，轮播图）
 */
@Controller
@RequestMapping("/sunday/mobile/advertisement")
@Api(value = "advertisement", description = "广告")
public class SundayFrontAdvertisementController extends BaseController {
    @Autowired
    private SundayFrontAdvertisementService advertisementService;


    /**
     * 广告信息HTML5
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping(value = "/html5", method = {RequestMethod.GET})
    @ApiOperation(value = "h5页面")
    public String html5(Model model,
                        HttpServletRequest request,
                        @ApiParam(value = "广告ID") @RequestParam(value = "id", required = true) long id
    ) {
        SundayAdvertisement advertisement = advertisementService.getById(id);
        model.addAttribute("advertisement", advertisement);
        return "/sunday/advertisement/html5";
    }

    /**
     * 查找单个
     *
     * @param request
     * @param response
     * @param id
     */
    @RequestMapping(value = "/findOne", method = {RequestMethod.GET})
    @ApiOperation(value = "查找单个")
    public void findOne(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "广告ID") @RequestParam(value = "id", required = true) long id
    ) {
        SundayAdvertisement result = advertisementService.getById(id);
        ResponseMessage.success(result);
    }

    /**
     * @param response
     * @param request
     * @param zoneKey
     */
    @RequestMapping(value = "/getAdvertisementByZoneKey", method = {RequestMethod.GET})
    @ApiOperation(value = "根据广告位获取广告信息(列表信息)。不分页")
    public void getAdvertisementByZoneKey(
            HttpServletResponse response,
            HttpServletRequest request,
            @ApiParam(required = true, name = "zoneKey", value = "广告位key。" +
                    "1，index_roll（首页轮播图,）2，bank（银行信息）")
            @RequestParam(value = "zoneKey", required = true) String zoneKey
    ) {
        List<SundayAdvertisementDto> result = advertisementService.getAdvertisementByZone(zoneKey);
        ResponseMessage.success(result);
    }
}
